angular.module('imsApp').controller('campaignsDetailController', ['$scope','$rootScope', '$state','CampaignsManager', function ($scope,$rootScope,$state,CampaignsManager) {

    var campaignsId = $state.params.campaignsId;
    CampaignsManager.campaignsDetail(campaignsId).then(function (result) {
        $scope.adCampaignVO = result.data.adCampaignVO;
        $scope.title = result.data.title;
        $scope.codeTable = JSON.parse(localStorage.getItem('codeTable'));

        if ($scope.adCampaignVO.intervalHourArray){
            $scope.adCampaignVO.intervalHourArray = $scope.adCampaignVO.intervalHourArray.split(',');
        }

        //详情-排期 字符串转换数组 [[],[],[]]
        if ($scope.adCampaignVO.scheduleDaysView !== undefined ) {
            var sourceArr = $scope.adCampaignVO.scheduleDaysView;
            var resultArr = [];
            for(var i = 0; i < sourceArr.length; i++) {
                var j = parseInt(i / 3);
                if(angular.isUndefined(resultArr[j])) {
                    resultArr[j] = [];
                }
                resultArr[j].push(sourceArr[i]);
            }
            $scope.adCampaignVO.scheduleDaysView = resultArr;
        }

    });

}]);

